package com.example.applicationone;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.RadioGroup;
import android.widget.RatingBar;
import android.widget.SeekBar;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;

public class HomeActivity extends AppCompatActivity {

    TextView textView;
    Button leftBtn, rightBtn, confimBtn;
    ProgressBar progressBar;
    Switch aSwitch;
    EditText editText;
    RadioGroup radioGroup;
    ImageView imageView;
    CheckBox checkBoxChinese, checkBoxMath, checkBoxEnglish;
    RatingBar ratingBar;
    SeekBar seekBar;
    String chinese, math, english;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);

        testUI();
    }

    void testUI() {
        textView = findViewById(R.id.textView);
        textView.setTextSize(20);
        leftBtn =findViewById(R.id.button2);
        rightBtn =findViewById(R.id.button3);
        confimBtn =findViewById(R.id.button4);
        progressBar =findViewById(R.id.progressBar3);
        aSwitch =findViewById(R.id.switch1);
        editText = findViewById(R.id.editTextNumber);
        radioGroup = findViewById(R.id.radioGroup);
        imageView = findViewById(R.id.imageView);
        checkBoxChinese = findViewById(R.id.checkBox);
        checkBoxMath = findViewById(R.id.checkBox2);
        checkBoxEnglish = findViewById(R.id.checkBox3);
        ratingBar = findViewById(R.id.ratingBar);
        seekBar = findViewById(R.id.seekBar);
        textView.setText("Home");
        leftBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                textView.setText(R.string.btn_left);
            }
        });
        rightBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                textView.setText(R.string.btn_right);
            }
        });
        aSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (b) {
                    textView.setText("开");
                }else {
                    textView.setText("关");
                }
            }
        });
        confimBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String value = editText.getText().toString();
                if (TextUtils.isEmpty(value)) { value = "0"; }
                progressBar.setProgress(Integer.valueOf(value));
            }
        });
        radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                if (i==R.id.radioButton) {
                    imageView.setImageResource(R.drawable.icon);
                } else {
                    imageView.setImageResource(R.drawable.ic_launcher_background);

                }
            }
        });
        ratingBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
            @Override
            public void onRatingChanged(RatingBar ratingBar, float v, boolean b) {
                Toast.makeText(getApplicationContext(), String.valueOf(v), Toast.LENGTH_SHORT).show();
            }
        });
        seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
                textView.setText(String.valueOf(i));
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });
        checkBoxChinese.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (b) {
                    chinese = "语文";
                } else  {
                    chinese = "";
                }
                textView.setText(chinese + math + english);

            }
        });
        checkBoxMath.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (b) {
                    math = "数学";
                } else  {
                    math = "";
                }
                textView.setText(chinese + math + english);

            }
        });
        checkBoxEnglish.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (b) {
                    english = "英语";
                } else  {
                    english = "";
                }
                textView.setText(chinese + math + english);

            }
        });
    }
}